package com.liuyubo.sort;

import java.util.Arrays;

/**
 * 选择排序
 */
public class SelectionSort implements Sort {

    @Override
    public void sort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[minIndex] > arr[j]) {
                    minIndex = j;
                }
            }
            swap(arr, i, minIndex);
        }
    }

    @Override
    public String getName() {
        return "Selection Sort";
    }

    public static void main(String[] args) {
        int[] arr = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
        SelectionSort sort = new SelectionSort();
        sort.sort(arr);
        Arrays.stream(arr).forEach(System.out::println);
    }
}
